/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package iconintable;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JTable;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import javax.swing.table.JTableHeader;

/**
 *
 * @author akosev
 */
class RowHeaderRenderer extends JLabel implements ListCellRenderer {

  RowHeaderRenderer(JTable table) {
    JTableHeader header = table.getTableHeader();
    setOpaque(true);
    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
    setHorizontalAlignment(CENTER);
    // belows do not work, i don't know why
    //setForeground(header.getForeground());
    //setBackground(header.getBackground());
    setFont(table.getFont());
  }


  public Component getListCellRendererComponent( JList list,
         Object value, int index, boolean isSelected, boolean cellHasFocus) {
      //the line below tell us, that
      //if (value==null) then setText(""), else setText(value.ToString())
    setText((value == null) ? "" : value.toString());
    return this;
  }
}
